<?php

//downErWeiMa($_GET['starTime'],$_GET['endTime'],$_GET['shengFeng']);

ini_set("display_errors", "On");

downExcelAll();

function downExcelAll(){



	//$qure='SELECT tell,CONCAT(shengFen,",",city) AS dizhi,riqi FROM everydaytell  WHERE riqi BETWEEN "'.$_GET['starTime'].'" AND "'.$_GET['endTime'].'"';

	$qure="SELECT start_date AS '报名时间',title AS '姓名',link_url AS '手机号码',SUBSTRING(special,INSTR(special,'_')+1,LENGTH(special)) AS '省份',SUBSTRING_INDEX(special,'_',1) AS '城市' FROM youjutell WHERE NAME IN ('河北591','河北优居','河北鼎盛','开信河北') AND start_date BETWEEN '".$_GET['starTime']."' AND  '".$_GET['endTime']."' ORDER BY SUBSTRING_INDEX(special,'_',1) DESC;";


	$host='localhost';
	$user='root';
	$password='root';
	$database='weizandata';
	$link=mysqli_connect($host, $user, $password, $database);
	$link->query("set names utf8");
	$result=mysqli_query($link, $qure);
	$arr=mysqli_fetch_all($result, 1);

	//var_dump($arr);

	require_once '../PHPExcel-1.8/Classes/PHPExcel.php';

	$excelFiled=array("报名时间","姓名","手机号码","省份","城市");

	//var_dump($excelFiled);

	$row=1;

	$objPHPExcel=new PHPExcel();

	$objPHPExcel->getActiveSheet()->fromArray($excelFiled,'A1');

	for($i=0;$i<count($arr);$i++){

		//$disCity=$arr['tell'][$i];

	 	$row+=1;

	 	$objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $arr[$i]['报名时间']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('B'.$row,$arr[$i]['姓名']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('C'.$row, $arr[$i]['手机号码']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('D'.$row, $arr[$i]['省份']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('E'.$row, $arr[$i]['城市']);


	}

	$objWriter =PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007');

	$nameFile=$_GET['fileName'];

	$objWriter->save("../excel/{$nameFile}");  // //excel/二维码.xlsx

	if(isset($_GET['getType'])){

		header("Location: ../excel/{$nameFile}");

	}

	
}

?>